//
//  TabBarC.swift
//  xiaofenshu
//
//  Created by 朱金龙 on 2021/5/19.
//

import UIKit
import YPImagePicker

class TabBarC: UITabBarController, UITabBarControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        delegate = self
    }
    

    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        if viewController is PostVc {
            
            let picker = YPImagePicker(configuration: ImagePickerConfig())
            picker.didFinishPicking {[unowned picker](items, cancelled) in
                if cancelled {
                    print("取消了")
                }
                for item in items {
                    switch item {
                    case .photo:
                        break
                    case .video:
                        break
                    }
                }
                picker.dismiss(animated: false, completion: nil)
            }
            
            present(picker, animated: true, completion: nil)
            return false
        }
        return true
    }
    
    
    func ImagePickerConfig() -> YPImagePickerConfiguration {
        var config = YPImagePickerConfiguration()
        config.albumName = Bundle.main.appName
        config.isScrollToChangeModesEnabled = false
        config.onlySquareImagesFromCamera = false
        config.startOnScreen = .library
        config.screens = [.library, .photo, .video]
        config.maxCameraZoomFactor = kMaxCameraZoomFactor
        
        
        // MARK: 相册配置
        config.library.mediaType = .photo
        config.library.defaultMultipleSelection = true
        config.library.maxNumberOfItems = kMaxPhoneCount
        config.library.spacingBetweenItems = kSpacingBetweenItems
        
        // MARK: 视频配置
        
        
        // MARK: 画廊展示
        config.gallery.hidesRemoveButton = false
        
        return config
    }

}
